<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>可选链操作符</title>
</head>

<body>
    <script>
        function main(config) {
            const dbHost=config&&config.db&&config.db.host;
            console.log(dbHost)
            const dbHost1=config?.db?.host;
            console.log(dbHost1)
        }
        main({
            db: {
                host: '192.168.1.2'
            }
        })
    </script>
</body>

</html>